package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Cart;
import cn.wolfcode.trip.base.service.ICartService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author by mycp
 * @Classname CartController
 * @Description TODO 购物车控制器
 * @Date 2018/11/15 21:43
 */
@RestController
@RequestMapping("/carts")
public class CartController {

    @Autowired
    private ICartService cartService;
    /**
     * 获取用户购物车信息
     * 动作: GET
     * 参数: userId = xx
     */
    @GetMapping("/{userId}")
    public Object getCart(@PathVariable Long userId){
        List<Cart> carts =  cartService.getCart(userId);
        return carts;
    }

    /**
     * 添加购物车信息
     * @param cart
     * @return
     */
    @PostMapping
    public Object saveCart(Cart cart){
        JsonResult result = new JsonResult();
        cartService.saveCart(cart);
        return result;
    }

    /**
     * 删除指定的购车商品
     * @param cart
     */
    @DeleteMapping
    public void delete(Cart cart){
        cartService.delete(cart);
    }
}
